using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using WebCrawlerTools.search;
using System.IO;

namespace WebCrawlerTools.data
{
    public class DDataInfo
    {

        private SortedList pageUrlList = new SortedList();
        private SResult listPageData;
        private SResult detailPageData;

        public SResult ListPageData
        {
            get
            {
                return listPageData;
            }
        }

        public SResult DetailPageData
        {
            get
            {
                return detailPageData;
            }
        }
    
        public static void Store(SResult result, string path)
        {
            try
            {
                StreamWriter writer = new StreamWriter(path, true, Encoding.Default);
                writer.WriteLine(result.ToString());
                writer.Close();
            }
            catch (Exception e)
            {
                e.ToString();
            }
        }

        public void Clear()
        {
            listPageData = null;
            detailPageData = null;
            
        }

        public ArrayList GetDetailPageUrlList()
        {
            if (listPageData == null)
            {
                return new ArrayList();
            }
            return listPageData.GetValByKey("URL");
        }

        public void AddListPageData(SResult data)
        {
            if (listPageData == null)
            {
                listPageData = new SResult();
                listPageData.Title = data.Title;
            }
            listPageData.Add(data);
        }

        public void AddDetailPageData(SResult data)
        {
            if (detailPageData == null)
            {
                detailPageData = new SResult();
                detailPageData.Title = data.Title;
            }
            detailPageData.Add(data);
        }
    }
}
